<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="javax.servlet.jsp.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    // 数据库连接
    Class.forName("org.mariadb.jdbc.Driver");
    String jdbcUrl = "jdbc:mariadb://10.220.140.102:3366/studb11";
    String jdbcUsername = "stua";
    String jdbcPassword = "zHZUA65r";
    
    
    request.setCharacterEncoding("utf-8");
    String roomtype = request.getParameter("roomtype");
    double price = Double.parseDouble(request.getParameter("price"));
    String description = request.getParameter("description");

        Connection conn = DriverManager.getConnection(jdbcUrl, jdbcUsername, jdbcPassword);

        String sql = "INSERT INTO rooms(roomtype,price,description) VALUES('"+roomtype+"',"+price+",'"+description+"')";
        PreparedStatement statement = conn.prepareStatement(sql);
        System.out.println("sql=" + sql);

        int result = statement.executeUpdate();
        if (result > 0) {
            out.println("房源信息发布成功！");
        } else {
            out.println("房源信息发布失败。");
        }

        statement.close();
        conn.close();

%>